package net.wenku8.reader.view.rank

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.lifecycle.viewmodel.compose.viewModel
import net.wenku8.reader.LocalNavController
import net.wenku8.reader.ui.lite.LiteGroup
import net.wenku8.reader.ui.lite.LiteInput
import net.wenku8.reader.ui.lite.LiteLine
import net.wenku8.reader.ui.lite.LitePanel
import net.wenku8.reader.ui.lite.LiteTextButton
import net.wenku8.reader.ui.lite.LiteTextLink


@Composable
fun RankList() {
    val rankListViewModel = viewModel<RankListViewModel>()
    val navController = LocalNavController.current
    LitePanel(
        hostState = rankListViewModel.hostState,
        title = "文库排行榜"
    ) {
        Column{
            LiteGroup(text = "搜索")
            LiteInput("书名/作者", rankListViewModel.key)
            LiteLine {
                LiteTextButton(text = "搜书名") {
                    rankListViewModel.toSearch(navController, "articlename")
                }
                LiteTextButton(text = "搜作者") {
                    rankListViewModel.toSearch(navController, "author")
                }
            }
            LiteGroup(text = "排行榜")
            LazyColumn{
                items(items = rankListViewModel.rankMap.entries.toList()) { entry ->
                    LiteTextLink(text = entry.value) {
                        rankListViewModel.toRankDetail(navController, entry.key, entry.value)
                    }
                }
            }
        }
    }
}
